//
//  MSHUDAtmosphereView.m
//  BOPMSProgress
//
//  Created by zz on 6.11.23.
//

#import "MSHUDAtmosphereView.h"
#import "UIImage+OPUD.h"


#define MSATW 270
#define MSATH 166
@interface MSHUDAtmosphereView()

@property (nonatomic, strong) UIImageView *iconImageView;
@property (nonatomic, strong) UILabel *messagelabel;

@end

@implementation MSHUDAtmosphereView

-(UIColor*)colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha {
    return [UIColor colorWithRed:red/255.0 green:green/255.0 blue:blue/255.0 alpha:alpha];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.layer.cornerRadius = 14;
        self.layer.masksToBounds = YES;
        self.backgroundColor = [ UIColor whiteColor];
        
        CGFloat iW = 52;
        CGFloat iH = 52;
        CGFloat iX = (MSATW - iW) * 0.5;
        CGFloat iY = 20;
        self.iconImageView = [[UIImageView alloc] initWithFrame:CGRectMake(iX, iY, iW, iH)];
        self.iconImageView.image = [UIImage opudImageNamed:@"opb_tip_icon"];
        [self addSubview:self.iconImageView];
        
        CGFloat mX = 0;
        CGFloat mY = CGRectGetMaxY(self.iconImageView.frame) + 16;
        CGFloat mW = MSATW;
        CGFloat mH = 18;
        self.messagelabel = [[UILabel alloc] initWithFrame:CGRectMake(mX, mY, mW, mH)];
        self.messagelabel.textAlignment = NSTextAlignmentCenter;
        self.messagelabel.text = @"Face detection is complete";
        self.messagelabel.textColor = [self colorWithRed:0 green:0 blue:0 alpha:0.85];
        self.messagelabel.font = [UIFont systemFontOfSize:13];
        [self addSubview:self.messagelabel];
        
        CGFloat lineX = 0;
        CGFloat lineY = CGRectGetMaxY(self.messagelabel.frame) + 16;
        CGFloat lineW = MSATW;
        CGFloat lineH = 0.5;
        UIView * line = [[UIView alloc] initWithFrame:CGRectMake(lineX, lineY, lineW, lineH)];
        line.backgroundColor = [self colorWithRed:60 green:60 blue:67 alpha:0.36];
        [self addSubview:line];
        
        CGFloat bX = 0;
        CGFloat bY = CGRectGetMaxY(line.frame);
        CGFloat bW = MSATW;
        CGFloat bH = 43;
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(bX, bY, bW, bH);
        [btn setTitleColor:[self colorWithRed:29 green:206 blue:159 alpha:1] forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont fontWithName:@"SFUIText-Semibold" size:17];
        [btn setTitle:@"Confirm" forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btn];
        
        
        
    }
    return self;
}

-(void)setConfigHandler:(configClickBlock _Nonnull)configHandler {
    _configHandler = [configHandler copy];
}

- (void)btnClick {
    if (self.configHandler) {
        self.configHandler();
    }
}

- (CGSize)intrinsicContentSize {
    return CGSizeMake(MSATW, MSATH);
}
@end
